package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("分页")
    public ResponseResult<PageResponse<UserVo>> findUserVoPage(
            @RequestBody UserDto userDto,
            @PathVariable("pageNum") int pageNum,
            @PathVariable("pageSize") int pageSize) {
        PageResponse<UserVo> userVoPage = userService.findUserPage(userDto, pageNum, pageSize);
        return ResponseResult.success(userVoPage);
    }

    @PutMapping
    @ApiOperation("用户添加")
    public ResponseResult createUser(@RequestBody UserDto userDto) {
        userService.addUser(userDto);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation("用户修改")
    public ResponseResult updateUser(@RequestBody UserDto userDto) {
        userService.updateUser(userDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/remove/{userId}")
    @ApiOperation("用户删除")
    public ResponseResult removeUser(@PathVariable("userId") Long userId) {
        userService.deleteUser(userId);
        return ResponseResult.success();
    }

    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation("用户启用禁用")
    public ResponseResult isEnable(@PathVariable("id") Long id, @PathVariable("status") String status) {
        userService.isEnable(id, status);
        return ResponseResult.success();
    }
    @PutMapping("/list")
    @ApiOperation("用户列表")
    public ResponseResult<UserVo> userList(@RequestBody UserDto userDto) {
        PageResponse<UserVo> userPage = userService.findUserPage(userDto, 1, 10);
        return ResponseResult.success(userPage);
    }

    @PostMapping("/reset-passwords/{userId}")
    @ApiOperation("重置密码")
    public ResponseResult resetPasswords(@PathVariable("userId") Long userId) {
        userService.resetPasswords(userId);
        return ResponseResult.success();
    }


}
